package com.imooc.dto.address;

import com.imooc.common.constants.ResultCodeConstants;
import com.imooc.common.exception.ValidateException;
import com.imooc.common.result.AbstractRequest;
import com.imooc.common.result.ResponseUtils;
import com.imooc.common.utils.MobileEmailUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName: AddAddressRequest
 * @Description:
 * @author: limingxing
 * @Date: 2019-12-26 11:08
 */
@Data
@ApiModel(value = "添加用户地址请求参数")
public class AddAddressRequest extends AbstractRequest {

    @ApiModelProperty(value = "关联用户id")
    private String userId;
    @ApiModelProperty(value = "收件人姓名")
    private String receiver;
    @ApiModelProperty(value = "收件人手机号")
    private String mobile;
    @ApiModelProperty(value = "省份")
    private String province;
    @ApiModelProperty(value = "城市")
    private String city;
    @ApiModelProperty(value = "区县")
    private String district;
    @ApiModelProperty(value = "详细地址")
    private String detail;

    @Override
    public void requestCheck() {
        if (StringUtils.isBlank(receiver)) {
            throw new ValidateException(ResultCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    "收货人不能为空");
        }
        if (receiver.length() > 12) {
            throw new ValidateException(ResultCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    "收货人姓名不能太长");
        }

        if (StringUtils.isBlank(mobile)) {
            throw new ValidateException(ResultCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    "收货人手机号不能为空");
        }
        if (mobile.length() != 11) {
            throw new ValidateException(ResultCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    "收货人手机号长度不正确");
        }
        boolean isMobileOk = MobileEmailUtils.checkMobileIsOk(mobile);
        if (!isMobileOk) {
            throw new ValidateException(ResultCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    "收货人手机号格式不正确");
        }
    }
}
